<?php


namespace App\Http\Controllers\Forwarder;


use App\Http\Controllers\Controller;
use App\Models\ForwarderLineComment;
use App\Models\Order;
use Illuminate\Http\Request;

class ForwarderLineCommentController extends Controller
{
    public function index(Request $request)
    {
        $list = ForwarderLineComment::where('forwarder_id', $request->input('forwarder_id'))->orderBy('id', 'desc')->paginate();
        return $this->response($list);
    }

    public function store(Request $request, ForwarderLineComment $obj)
    {
        $order = Order::where('id', $request->input('order_id'))->where('user_id', $request->user()->id)->first();
        if ($order !== 2){
            abort(5072);
        }
        $all = $request->all();
        $obj->fill($all);
        $obj->user_id = $request->user()->id;
        $obj->forwarder_id = $order->forwarder_id;
        $obj->save();
        return $this->response();
    }
}
